package com.example.deptconsumer80;

import com.example.myrule.MySelfRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RetryRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName: DeptConsumer80App
 * @Author: liugui
 * @Date: 2020-09-19 09:54
 **/
@SpringBootApplication
@EnableEurekaClient
@RibbonClient(name = "DEPT-SERVICE",configuration = MySelfRule.class)
public class DeptConsumer80App {

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    //@Bean
    public IRule config(){
        //RoundRobinRule 轮询
        //RandomRule 随机
        return new RetryRule();//轮询中发现不可用，则不使用 选择其他可用服务
    }

    //配置Ribbon

    public static void main(String[] args) {
        SpringApplication.run(DeptConsumer80App.class);
    }
}
